package cn.snorlaxzjt.LBSserver.controller;

import cn.snorlaxzjt.LBSserver.business.UserBusiness;
import cn.snorlaxzjt.LBSserver.common.BusinessCode;
import cn.snorlaxzjt.LBSserver.common.EmailConfig;
import cn.snorlaxzjt.LBSserver.common.Result;
import cn.snorlaxzjt.LBSserver.po.body.RegisterBody;
import cn.snorlaxzjt.LBSserver.po.entity.User;
import cn.snorlaxzjt.LBSserver.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/sso")
@Api(value = "UserController")
public class UserController {

    @Resource
    private UserBusiness userBusiness;

    /**
     * 注册
     *
     * @param
     * @return Result
     */
    @PostMapping(value = "/register")
    public Result<User> regist(@RequestBody RegisterBody body) {
        User user = new User(body.getUsername(), "defaultAvatar.jpg", body.getEmail());
        user.setPassword(body.getPassword());
        return userBusiness.register(user, body.getCode());
    }

    /**
     * 登录
     *
     * @param email
     * @param password
     * @return
     */
    @ApiOperation(value = "")
    @PostMapping("/login")
    public Result<Map<String, String>> login(@RequestParam String email,
                        @RequestParam String password) {
        return userBusiness.login(email,password);
    }

//    @PostMapping("/updateUserInfo")
//    public Result<Void> updatePassword(@RequestBody User user) {
//
//    }

}
